package com.xiaolin.spring.annotation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
 * @ClassName ADemoTest
 * @Description TODO
 * @Detail 基于注解的配置
 * @Author MyPC
 * @Date 2020/10/27
 * @Version 1.0
 */
public class ADemoTest3 {

    private Optional<DBean> dBean;

    /**
     * 使用Optional集合，就算dBean对象没有载容器中，也不会报错
     * @param dBean
     */
    @Autowired
    public void setdBean(Optional<DBean> dBean) {
        this.dBean = dBean;
    }

    public static void main(String[] args) {
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("a-demo-test.xml");
        ADemoTest3 ad = applicationContext.getBean("ad3", ADemoTest3.class);
        System.out.println(ad.dBean);
    }
}
